package test_202203;

import java.util.HashSet;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        HashSet<Integer> set=new HashSet<>();
        int left;
        int right;
        int res=0;
        for(int i=0;i<k;i++){
            left=sc.nextInt();
            right=sc.nextInt();
            if(right!=0){
                if(set.contains(right)){
                    set.add(left);
                    continue;
                }else{
                    set.add(left);
                    res++;
                }
            }else{
                set.add(left);
            }

        }
        sc.close();
        System.out.println(res);
    }
    
}
